package com.yanqu.road.entity.activity.worldcup;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.config.system.NormalWeightItem;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

@FieldTypeAnnotation(tableName = "t_s_activity_worldcup_skill")
public class WorldCupSkillConfig {

    @FieldTypeAnnotation(select = true, desc = "活动id")
    private int activityId;
    @FieldTypeAnnotation(desc = "解数类型")
    private int type;
    @FieldTypeAnnotation(desc = "解数等级")
    private int level;
    @FieldTypeAnnotation(desc = "图标")
    private String icon;
    @FieldTypeAnnotation(desc = "名字")
    private String name;
    @FieldTypeAnnotation(desc = "描述")
    private String desc;
    @FieldTypeAnnotation(desc = "升级需经验")
    private int cost;
    @FieldTypeAnnotation(desc = "招募配置")
    private String recruitInfo;

    private List<WorldCupRecruitInfo> recruits;
    private List<NormalWeightItem> weightRecruits;

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getCost() {
        return cost;
    }

    public void setCost(int cost) {
        this.cost = cost;
    }

    public String getRecruitInfo() {
        return recruitInfo;
    }

    public void setRecruitInfo(String recruitInfo) {
        this.recruitInfo = recruitInfo;

        this.recruits = new ArrayList<>();
        this.weightRecruits = new ArrayList<>();
        String[] attrs = this.recruitInfo.split("\\|");
        for (int i = 0; i < attrs.length; i++) {
            String[] recruitInfos = attrs[i].split(";");
            int quality = i + 1;
            int weight = Integer.valueOf(recruitInfos[1]);
            List<Integer> ranges = StringUtils.stringToIntegerList(recruitInfos[0], ",");
            WorldCupRecruitInfo ballerAbilityRange = new WorldCupRecruitInfo();
            ballerAbilityRange.setType(this.getType());
            ballerAbilityRange.setLevel(this.getLevel());
            ballerAbilityRange.setQuality(quality);
            ballerAbilityRange.setMinValue(ranges.get(0));
            ballerAbilityRange.setMaxValue(ranges.get(1));
            ballerAbilityRange.setWeight(weight);
            ballerAbilityRange.setValue(BigInteger.valueOf(quality));
            this.recruits.add(ballerAbilityRange);
            this.weightRecruits.add(ballerAbilityRange);
        }
    }

    public List<WorldCupRecruitInfo> getRecruits() {
        return recruits;
    }

    public List<NormalWeightItem> getWeightRecruits() {
        return weightRecruits;
    }

    public int getIdx() {
        return this.getType() * 10000 + this.getLevel();
    }
}
